from ctypes import *
import os

# 常量定义
NETDEV_LEN_260 = 260
NETDEV_LEN_132 = 132
NETDEV_LEN_128 = 128
NETDEV_LEN_64 = 64

load_library = cdll.LoadLibrary
net_sdk_dll_path = os.path.dirname(__file__) + '/lib/libNetDEVSDK.so'

class NETDEV_DEVICE_LOGIN_INFO_S(Structure):
    _fields_ = [
        ("szIPAddr", c_char * NETDEV_LEN_260),
        ("dwPort", c_int32),
        ("szUserName", c_char * NETDEV_LEN_132),
        ("szPassword", c_char * NETDEV_LEN_128),
        ("dwLoginProto", c_int32),
        ("dwDeviceType", c_int32),
        ("byRes", c_byte * 256),
    ]

class NETDEV_VIDEO_CHL_DETAIL_INFO_S(Structure):
    _fields_ = [
        ("dwChannelID", c_int32),
        ("bPtzSupported", c_bool),
        ("enStatus", c_int32),
        ("dwStreamNum", c_int32),
        ("szChnName", c_char * NETDEV_LEN_64),
        ("byRes", c_byte * 4),
    ]



class NETDEV_SELOG_INFO_S(Structure):
    _fields_ = [
        ("dwSELogCount", c_int32),
        ("dwSELogTime", c_int32),
        ("byRes", c_byte * 64),
    ]

# 指针类型
LPNETDEV_DEVICE_LOGIN_INFO_S = POINTER(NETDEV_DEVICE_LOGIN_INFO_S)
LPNETDEV_SELOG_INFO_S = POINTER(NETDEV_SELOG_INFO_S)

# 定义常量枚举（根据实际SDK中的定义）
NETDEV_TRANS_PROTOCAL_E = c_int  # 定义传输协议枚举
NETDEV_STORE_TYPE_E = c_int      # 定义存储类型枚举
NETDEV_E_DOWNLOAD_SPEED_E = c_int # 下载速度枚举
NETDEV_STREAM_MODE_E = c_int      # 流模式枚举
NETDEV_LIVE_STREAM_INDEX_E = c_int # 码流类型枚举
NETDEV_RECORD_LOCATION_E = c_int   # 录像位置枚举
NETDEV_TRANS_TYPE_E = c_int        # 传输类型枚举
NETDEV_VOD_PLAY_STATUS_E = c_int   # 播放速度枚举

# 定义回调函数类型
NETDEV_DECODE_VIDEO_DATA_CALLBACK_PF = CFUNCTYPE(None, c_void_p, c_int, c_void_p, c_int, c_int, c_int)

# 定义结构体
class NETDEV_PLAYBACKCOND_S(Structure):
    _fields_ = [
        ("dwChannelID", c_int32),
        ("tBeginTime", c_int64),
        ("tEndTime", c_int64),
        ("dwLinkMode", c_int32),
        ("hPlayWnd", c_void_p),
        ("dwFileType", c_int32),
        ("dwDownloadSpeed", c_int32),
        ("dwStreamMode", c_int32),
        ("dwStreamIndex", c_int32),
        ("dwRecordLocation", c_int32),
        ("dwTransType", c_int32),
        ("bCloudStorage", c_bool),
        ("bOneFrameEnable", c_bool),
        ("dwPlaySpeed", c_int32),
        ("cbPlayDecodeVideoCALLBACK", NETDEV_DECODE_VIDEO_DATA_CALLBACK_PF),
        ("tPlayTime", c_int64),
        ("udwServerID", c_uint32),
        ("udwStreamID", c_uint32),
        ("bStreamIDEnable", c_bool),
        ("udwRelationOfTypes", c_uint32),
        ("udwPosition", c_uint32),
        ("udwSessionID", c_uint32),
        ("byRes", c_byte * 192)
    ]

LPNETDEV_PLAYBACKCOND_S = POINTER(NETDEV_PLAYBACKCOND_S)
